package com.yiren.manager.service.impl.elder;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiren.core.exception.MyException;
import com.yiren.core.service.GenericServiceImpl;
import com.yiren.core.utils.Favorites;
import com.yiren.entity.YrBehalfElectricity;
import com.yiren.entity.YrElderArrearage;
import com.yiren.entity.YrElderPayRecord;
import com.yiren.entity.YrElderWallet;
import com.yiren.manager.repository.cost.YrElderArrearageRepository;
import com.yiren.manager.repository.cost.YrElderPayRecordRepository;
import com.yiren.manager.repository.elder.YrBehalfElectricityRepository;
import com.yiren.manager.repository.elder.YrElderWalletRepository;
import com.yiren.manager.service.iface.elder.YrBehalfElectricityService;

@Service
public class YrBehalfElectricityServiceImpl extends GenericServiceImpl<YrBehalfElectricity, String> implements YrBehalfElectricityService{
	
	@Autowired
	private YrElderWalletRepository elderWalletRepository;
	
	@Autowired
	private YrElderPayRecordRepository elderPayRecordRepository;
	
	@Autowired
	private YrElderArrearageRepository elderArrearageRepository;
	
	@Autowired
	public YrBehalfElectricityServiceImpl(YrBehalfElectricityRepository repository) {
		super(repository);
	}

	@Transactional
	public void addByFavorites(Favorites entitys) throws MyException {
		YrBehalfElectricity behalfElectricity = entitys.getFavorite(YrBehalfElectricity.class);
		YrElderWallet elderWallet = entitys.getFavorite(YrElderWallet.class);
		YrElderPayRecord elderPayRecord = entitys.getFavorite(YrElderPayRecord.class);
		YrElderArrearage elderArrearage = entitys.getFavorite(YrElderArrearage.class);
		
		this.repository.save(behalfElectricity);
	
		if(elderWallet!=null){
			elderWalletRepository.save(elderWallet);
		}
		if(elderPayRecord!=null){
			elderPayRecordRepository.save(elderPayRecord);	
		}
		if(elderArrearage!=null){
			elderArrearageRepository.save(elderArrearage);
		}
		
	}

	public void modifyByFavorites(Favorites entitys) throws MyException {
		// TODO Auto-generated method stub
		
	}

}
